﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Space_Conquest
{
    delegate void InGameButtonHandler();

    class InGameButton : IRender, IInput
    {


        #region Member Variables

        //private Sprite _sprButton = new Sprite(0, 0, 147, 32,255,false);
        //private Texture _texButton = new Texture("Images/InGameMenuButton.bmp");

        //private int _x = 0;
        //private int _y = 0;
        private int _x;
        private int _y;
        private int _sizeX;
        private int _sizeY;
        private string _texture;
        private Texture _texButton;
        private Sprite _sprButton;
        #endregion

        #region Member Variables

        public int X
        {
            get
            {
                return _x;
            }
        }

        public int Y
        {
            get
            {
                return _y;
            }
        }

        public int Width
        {
            get
            {
                return _sizeX;
            }
        }

        public int Height
        {
            get
            {
                return _sizeY;
            }
        }

        #endregion

        #region Contructor

        public InGameButton(int x, int y, int sizeX, int sizeY, string texture)//(int x, int y)
        {
            //_x = x;
            //_y = y;
            _x = x;
            _y = y;
            _sizeX = sizeX;
            _sizeY = sizeY;
            _texture = texture;
            _texButton = new Texture(_texture);
            _sprButton = new Sprite(x, y, sizeX, sizeY, 255, false);
        } 

        #endregion

        #region Events

        public event InGameButtonHandler OnButtonClick;
        

        #endregion

        #region IRender Members

        public void Render()
        {
            _sprButton.Right = _x;//Globals.iScreenWidth;
            _sprButton.Render(_texButton);
        }

        #endregion

        #region IInput Members

        public bool MouseDown(System.Windows.Forms.MouseButtons button, int x, int y)
        {
            if (x - Globals.iScreenOffsetX > _sprButton.Left && x - Globals.iScreenOffsetX < _sprButton.Right)
            {
                if (y - Globals.iScreenOffsetY > _sprButton.Top && y - Globals.iScreenOffsetY < _sprButton.Bottom)
                {
                    if (OnButtonClick != null)
                    {
                        OnButtonClick();
                        return true;
                    }
                }
            }
            return false;
        }

        public bool MouseUp(System.Windows.Forms.MouseButtons button, int x, int y)
        {
            return false;
        }

        public bool MouseMove(int x, int y)
        {
            return false;
        }

        public bool KeyDown(System.Windows.Forms.Keys key, bool shift)
        {
            return false;
        }

        public bool KeyUp(System.Windows.Forms.Keys key, bool shift)
        {
            return false;
        }

        #endregion


    }
}
